package com.jiazhong.boot.mvc.interceptor.config;

import com.jiazhong.boot.mvc.interceptor.interceptor.FirstInterceptor;
import com.jiazhong.boot.mvc.interceptor.interceptor.FourthInterceptor;
import com.jiazhong.boot.mvc.interceptor.interceptor.SecondInterceptor;
import com.jiazhong.boot.mvc.interceptor.interceptor.ThirdInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 对MVC进行配置的一个Configuration
@Configuration
public class SpringMVCConfig implements WebMvcConfigurer {
    @Resource
    private FirstInterceptor firstInterceptor;
    @Resource
    private SecondInterceptor secondInterceptor;
    @Resource
    private ThirdInterceptor thirdInterceptor;
    @Resource
    private FourthInterceptor fourthInterceptor;

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册了拦截器并设置对哪些请求进行拦截
        registry.addInterceptor(firstInterceptor)
                .addPathPatterns("/first/**")
                .excludePathPatterns("/first/a").order(1);

        registry.addInterceptor(secondInterceptor)
                .addPathPatterns("/**").order(7);

        registry.addInterceptor(thirdInterceptor)
                .addPathPatterns("/**").order(98);

        registry.addInterceptor(fourthInterceptor)
                .addPathPatterns("/**").order(3);
    }
}
